﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xiucai.BPM.Core.Model;
using Xiucai.Common.Data;
using Xiucai.Common.Provider;

namespace Xiucai.BPM.Core.Dal
{
    public class DevConfigDal : BaseRepository<DevConfig>
    {
        public static DevConfigDal Instance
        {
            get { return SingletonProvider<DevConfigDal>.Instance; }
        }

        public IEnumerable<DevConfig> GetListBy(string categoryCode)
        {
            return GetList("select * from dev_dev where code=@code", new { code = categoryCode });
        }
        public IEnumerable<string> GetHarms(object parameters)
        {
            return DbUtils.ExecuteReaderSpValueType<string>("ProGetUserHarms", parameters);
        }

        public IEnumerable<DevConfig> GetListBy(int categoryId)
        {

            return GetWhere(new { DevOwnerID = categoryId });

            //return GetList("select * from Dev_Dev", new { code = categoryId });
        }
        public IEnumerable<DevConfig> GetListBy(int categoryId,string type)
        {

            return GetWhere(new { DevOwnerID = categoryId, DevType=type });

            //return GetList("select * from Dev_Dev", new { code = categoryId });
        }
        public IEnumerable<DevConfig> GetListByKeyid(int keyId)
        {

            return GetWhere(new { KeyId = keyId });

            //return GetList("select * from Dev_Dev", new { code = categoryId });
        }
        public IEnumerable<DevConfig> GetListByPhone(string phone)
        {

            return GetWhere(new { DevContact=phone });

            //return GetList("select * from Dev_Dev", new { code = categoryId });
        }

        public IEnumerable<DevConfig> GetListBy(int categoryId, int roleID)
        {

            if (categoryId==0)//roleID == 888
            {
                //return GetWhere(new { IsDisabled = false});
                return GetList("select * from dev_dev where DevOwnerID!=@code", new { code = 0 });
            }
            else
            {
                return GetWhere(new { DevOwnerID = categoryId });
            }

            //return GetList("select * from Dev_Dev", new { code = categoryId });
        }
    }
}
